import Mock from "mockjs";
import { HistoryInfos } from "./model/HistoryInfo";
import { IHistoryInfo } from "@/model/HistoryInfo";

Mock.mock(/api\/HistoryInfos\/.*/, "get", function(options: any): IHistoryInfo {
  const list: string[] = options.url.split("/");
  const ID = list[list.length - 1];
  return HistoryInfos.Instance().Read(ID)!;
});

Mock.mock(/api\/HistoryInfos/, "get", function(): IHistoryInfo[] {
  return HistoryInfos.Instance().ReadAll();
});

// 创建
Mock.mock(/api\/HistoryInfos/, "post", function(options: any): IHistoryInfo {
  const data: IHistoryInfo = JSON.parse(options.body).data;
  return { ID: HistoryInfos.Instance().Create(data.Type) };
});

Mock.mock(/api\/HistoryInfos/, "put", function(options: any) {
  const data: IHistoryInfo = JSON.parse(options.body).data;
  return {
    response: HistoryInfos.Instance().Update(data.ID!, data.Histories!)
  };
});
